// Register page module
// ====================

define(['zepto', 'wx', 'sui', 'submitForm'], function($, wx) {
  return {
    init: function(data) {
    	this.data = data;
      this.monthlyId = data.monthlyId;
      this.batchId = data.batchId;
      this.unitId = data.unitId;
      this.inviter = data.inviter;
      this.bindClick();
      var shareData = this.initShareData();
      var isDebug = location.search.indexOf('debug=true') > 0
      wx.config({
        debug: isDebug,
        appId: data.jsConfig.appid,
        timestamp: data.jsConfig.timestamp,
        nonceStr: data.jsConfig.nonceStr,
        signature: data.jsConfig.signature,
        jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
      })
      wx.ready(function() {
        wx.onMenuShareTimeline({
          title: shareData.name,
          desc:  shareData.desc,
          link:  shareData.link,
          imgUrl: shareData.cover
        })
        wx.onMenuShareAppMessage({
          title: shareData.name,
          desc:  shareData.desc,
          link:  shareData.link,
          imgUrl: shareData.cover
        })
      })
    },
    initShareData: function() {
      var that = this;
      return {
        name:  "每天10分钟，一起运动来打卡～",
        desc:  "每天10分钟，运动小打卡。今天是我第"+that.data.signinDays+"天运动打卡，已在人马君运动打卡计划中坚持运动"+that.data.signinMinutes+"分钟啦！",
        link:   window.__CTX__.domain + "/courses/" + this.monthlyId + "/batches/" + this.batchId + "/units/" + this.unitId + "/result-share?inviter=" + that.inviter,
        cover:  window.__CTX__.domain + "/resource/image/daily-clock.jpg"
      }
    },
    bindClick: function() {
      $(document).on("click", ".share-btn", function(e) {
       e.preventDefault();
        var modalHtml = '<div class="modal-overlay share-modal">' +
                          '<div class="modal-descrption"><p style="left: 2.5rem; bottom: 1.5rem;">点击右上角，<br/>分享到朋友圈</p>'+
                          '<img src="'+ window.__CTX__.resource +'/image/share-hint.png" width="100%">'+
                        '</div></div>'
        $("body").append(modalHtml)
      })
    
      $(document).on("click", ".share-modal", function(e) {
        e.preventDefault();
        $(this).remove();
      })
    }
   
  }
})